#include "Stdafx.h"
#include "NX2DObjectAPI.h"
//#include "TPSVGParser.h"
#include "ModelInterior.h"
#include "TP_Text3DOutline.h"
#include "NXCircleModel.h"
#include "NXPolygonModel.h"
#include "ArrowModel.h"
BOOL CreateIsogon(LPVOID pObjectParam,OUT TPOUTLINEFIGURE& ObjectFigure )
{
	NXIsogon* pParam  = (NXIsogon*)pObjectParam;
	pParam->fRadius = pParam->fRadius<1?1:pParam->fRadius;
	int nCount = int(2*3.14159265f*pParam->fRadius);
	nCount = 1001;
	ObjectFigure.nPointCount = nCount;
	ObjectFigure.pdwType = new DWORD[nCount];
	ObjectFigure.pfX = new float[nCount];
	ObjectFigure.pfY = new float[nCount];
	ObjectFigure.nDirect = 0;
	
	float fDelta = 10.0f;
	ObjectFigure.pdwType[0] = TP_PRIM_FIGURESTART;
	ObjectFigure.pfX[0] = pParam->fRadius* cos(fDelta) + pParam->ptCenter.x;
	ObjectFigure.pfY[0] = pParam->fRadius* sin(fDelta) + pParam->ptCenter.y;

	float fTheta = 0.0f;
	for (int i=1;i<nCount-1;i++) 
	{
		fTheta = i*2*PI / (nCount-1)+fDelta ;
		ObjectFigure.pdwType[i] = TP_PRIM_LINE;
		ObjectFigure.pfX[i] = pParam->fRadius * cos(fTheta) + pParam->ptCenter.x;
		ObjectFigure.pfY[i] = pParam->fRadius * sin(fTheta) + pParam->ptCenter.y;
	}

	ObjectFigure.pdwType[nCount-1] = TP_PRIM_LINE;
	ObjectFigure.pfX[nCount-1] = pParam->fRadius* cos(fDelta) + pParam->ptCenter.x;
	ObjectFigure.pfY[nCount-1] = pParam->fRadius* sin(fDelta) + pParam->ptCenter.y;

	return TRUE;
}

BOOL CreateSVG(LPVOID pObjectParam,OUT TPOUTLINEFIGURE& ObjectFigure )
{
	
	return TRUE;
}

BOOL CreateTextFigure(LPVOID pObjectParam,OUT TPOUTLINEFIGURE& ObjectFigure)
{
	NXTextOutLine* pParam = (NXTextOutLine*)pObjectParam;
	
	TEXTMULTIPOLYGONS textMultiPolygons;
	
	TP3D_GetTextMultiOutline(pParam->h_font,pParam->pChar,pParam->nCharNum,textMultiPolygons);

	std::vector<POINTF> TarrVectices;
	std::vector<std::vector<std::vector<int>>> TarrProfiles;
	TP3D_TextDataInterface(&textMultiPolygons,TarrVectices,TarrProfiles);

	NX_ConvertToFigure(TarrVectices,TarrProfiles,ObjectFigure);
	
	return TRUE;
}

BOOL CreateCircle(LPVOID pObjectParam,OUT TPOUTLINEFIGURE& ObjectFigure)
{
	NXCircle* pParam = (NXCircle*)pObjectParam;
	return NXCreateCircle(pParam->fWidth,pParam->fHeight,pParam->fStartRad,pParam->fEndRad,pParam->eType,ObjectFigure);	
}

BOOL CreatePolygon(LPVOID pObjectParam,OUT TPOUTLINEFIGURE& ObjectFigure)
{
	NXPolygon* pParam = (NXPolygon*)pObjectParam;
	NXCreatePolygon(pParam,ObjectFigure);
	return TRUE;	
}

BOOL CreateArrow(LPVOID pObjectParam,OUT TPOUTLINEFIGURE& ObjectFigure)
{
	NXArrow* pParam = (NXArrow*)pObjectParam;
	NXCreateArrow(pParam,ObjectFigure);
	return TRUE;	
}


AFX_EXT_API BOOL NXCreateModel( eObejctType eType, LPVOID pObjectParam,OUT TPOUTLINEFIGURE& ObjectFigure )
{
	switch(eType)
	{
	case eIsogon:
		CreateIsogon( pObjectParam, ObjectFigure);
		break;
	case eSVGCurve:
		//CreateSVG( pObjectParam, ObjectFigure);
		break;
	case ePolygon:
		CreatePolygon( pObjectParam, ObjectFigure);
		break;
	case eText:
		CreateTextFigure( pObjectParam, ObjectFigure);
		break;
	case eCircle:
		CreateCircle(pObjectParam,ObjectFigure);
		break;
	case eArrow:
		CreateArrow(pObjectParam,ObjectFigure);
		break;
	}
	return TRUE;
}
